<template>
    <div>
        <!-- 顶部滚动条 -->
        <div id="slider" class="photo-list mui-slider">
            <div id="sliderSegmentedControl"
                 class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
            >

                <div class="mui-scroll">
                    <a :class="['mui-control-item', item.id===0 ? 'mui-active' : '']"
                       href="#item1mobile"
                       data-wid="tab-top-subpage-1.html"
                       v-for="item in topList" :key="item.id"
                       @click.prevent="getPhotoList(item.id)"
                    >
                        {{item.title}}
                    </a>
                </div>

            </div>

        </div>
        <!-- 图片列表 -->
        <ul class="photo-list-ul">
            <router-link v-for="item in photoList" :key="item.id" :to="'/home/photoinfo/' + item.id" tag="li">
                <img v-lazy="item.image">
                <div class="info">
                    <div class="descrition">
                        <span >{{item.desc}}</span>
                    </div>
                </div>
            </router-link>
        </ul>

    </div>
</template>

<script>
    import mui from '../../lib/mui/js/mui.min.js'
    import {Toast} from 'mint-ui'
    export default {
        data:function () {
            return {
                topList:null,
                photoList:[],
            }
        },
        created(){
            this.getTopCategaray();
            this.getPhotoList('0');
        },
        mounted(){
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
            });
        },
        methods:{
            getTopCategaray(){
                this.$http.get('http://rap2api.taobao.org/app/mock/149003/photo/topList')
                    .then((resultObject)=>{
                        var result = resultObject.body;
                        if (parseInt(result.status) === 200) {
                            this.topList = result.list;
                            this.topList.unshift({id:0, title:'全部'})
                        } else {
                            Toast("请求失败")
                        }
                    })
            },
            getPhotoList(needId){
                this.$http.get('http://rap2api.taobao.org/app/mock/149003/photo/photoList/' + needId)
                    .then((resultData)=>{
                        var result = resultData.body;
                        if (parseInt(result.status) === 200) {
                            this.photoList = result.list;
                        } else {
                            Toast("请求失败")
                        }
                    })
            },
            test () {
                var regex = /(\d{4})-(\d{2})-(\d{2})/
                var str = '2019-12-08'
                console.log(str.match(regex))
            }

        }
    }

</script>

<style scoped lang="scss">

    .photo-list-ul {
        padding: 10px;
        margin: 0;
        list-style: none;
        padding-top: 0;
        background-color: #fff;
        li {
            position: relative;
            box-shadow: 0 0 9px #999;
            padding-bottom: 10px;
            img {
                width: 100%;
                height: 220px;
            }
            img[lazy=loading] {
                width: 40px;
                height: 300px;
                margin: auto;
            }
            .info {
                background-color: rgba(0,0,0, 0.5);
                padding: 10px;
                position: absolute;
                bottom: 10px;
                max-height: 90px;
                .descrition {
                    color: #ffffff;
                    font-size: 12px;
                    text-align: center;
                }

            }

        }
    }

</style>
